﻿define(['plugins/router', 'knockout', 'durandal/system'], function(router, ko, system) {
    var masterVm = ko.observable();

    var childRouter = router
        .createChildRouter()
        .makeRelative({ moduleId:'app-samples/keyedMasterDetail', fromParent:true, dynamicHash:':id' })
        .map([
            { route: ['first', ''], moduleId: 'first',  title: 'First', nav: true, hash: '#first' },
            { route:'second',       moduleId:'second',  title:'Second', nav:true },
            { route:'third',        moduleId:'third',   title:'Third',  nav:true }
        ]).buildNavigationModel();

    var vm = {
        router:childRouter,
        activate:activate,
        deactivate:deactivate,
        masterVm:masterVm
    };

    return vm;

    function activate(id,splat) {
        system.log('Master View ' + id + ' Activated');
        loadObservables(id);
//      return loadObservables(id);//return与否没卵用，只有promise才有用
    }

    function deactivate() {
        system.log('Master View ' + masterVm().id + ' Deactivated');
    }

    function loadObservables(id) {
        masterVm({ id:id, name:'Master' });
    }
});